using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;

namespace WindowsFormsApplication1
{
    public partial class rptTKSVTheoDanToc : DevExpress.XtraReports.UI.XtraReport
    {
        CalculatedField Percent_Nam = new CalculatedField();
        CalculatedField Percent_Nu = new CalculatedField();
        CalculatedField Percent_TongNam = new CalculatedField();
        CalculatedField Percent_TongNu = new CalculatedField();
        XRSummary Sum_Nam;
        XRSummary Sum_Nu;
        XRSummary Sum_Siso;
        int STT = 0;
        public rptTKSVTheoDanToc()
        {
            InitializeComponent();
            CalculatedFields.AddRange(new CalculatedField[] { Percent_Nam, Percent_Nu });
        }

        private void colSTT_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            STT++;
            colSTT.Text = STT.ToString();
        }

        public void BindData(string tunam, string dennam)
        {
            colTunam.Text = tunam;
            colDennam.Text = dennam;
            colMadantoc.DataBindings.Add("Text", DataSource, "MadantocID");
            colTendantoc.DataBindings.Add("Text", DataSource, "Tendantoc");
            colSLNam.DataBindings.Add("Text", DataSource, "Nam");
            colSLNu.DataBindings.Add("Text", DataSource, "Nu");
            colSiso.DataBindings.Add("Text", DataSource, "Siso");
            //Tinh tong so luong nam
            Sum_Nam = new XRSummary();
            colSum_Nam.DataBindings.AddRange(new XRBinding[] { new XRBinding("Text", null, "Nam", "") });
            Sum_Nam.Running = SummaryRunning.Report;
            colSum_Nam.Summary = Sum_Nam;

            //Tinh tong so luong nu
            Sum_Nu = new XRSummary();
            colSum_Nu.DataBindings.AddRange(new XRBinding[] { new XRBinding("Text", null, "Nu", "") });
            Sum_Nu.Running = SummaryRunning.Report;
            colSum_Nu.Summary = Sum_Nu;
            //Tinh Tong si so
            Sum_Siso = new XRSummary();
            colSum_Siso.DataBindings.AddRange(new XRBinding[] { new XRBinding("Text", null, "Siso", "") });
            Sum_Siso.Running = SummaryRunning.Report;
            colSum_Siso.Summary = Sum_Siso;
            //Tinh %Nam
            colPercentNam.DataBindings.AddRange(new XRBinding[] { new XRBinding("Text", null, "percent_nam", "{0:0.0%}") });
            Percent_Nam.Expression = "[Nam] / ([Nam] + [Nu])";
            Percent_Nam.FieldType = FieldType.Float;
            Percent_Nam.Name = "percent_nam";
            //Tinh %Nu
            colPercentNu.DataBindings.AddRange(new XRBinding[] { new XRBinding("Text", null, "percent_nu", "{0:0.0%}") });
            Percent_Nu.Expression = "[Nu] / ([Nam] + [Nu])";
            Percent_Nu.FieldType = FieldType.Float;
            Percent_Nu.Name = "percent_nu";
        }

        private void colPercent_TongNam_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            float TongNam = float.Parse(Sum_Nam.GetResult().ToString());
            float TongsiSo = float.Parse(Sum_Siso.GetResult().ToString());
            colPercent_TongNam.Text = (TongNam / TongsiSo).ToString("0.0%");
        }

        private void colPercent_TongNu_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            float Tongnu = float.Parse(Sum_Nu.GetResult().ToString());
            float TongsiSo = float.Parse(Sum_Siso.GetResult().ToString());
            colPercent_TongNu.Text = (Tongnu / TongsiSo).ToString("0.0%");
        }

    }
}
